<?php 
  include "inc/conn.php";
  include "config.php";
  $tts = date("YmdHis",time());
  // $tts = date("Y-m-d H:i:s",time());
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes" />
<title><?php echo $title;?></title>
<meta name="author" content="andy - vip@d163.net">
<meta name="copyright" content="www.d163.net">
<link href="https://lib.baomitu.com/twitter-bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="http://at.alicdn.com/t/font_374778_eq952jykmer.css">
<link href="inc/css/wap.css?v=<?php echo $tts;?>" rel="stylesheet" type="text/css" />
<script src="inc/js/ajax_wap.js?v=<?php echo $tts;?>" type="text/javascript"></script>
<style>
  .top-ico .iconfont {font-size: 94px; color: #09BB07; }
  .top-ico {text-align: center; }
  .msg-box-txt {text-align: center; }
  .top-ico .iconfont.icon-warn {color: red; }
  .manage {position: absolute; right: 6px; top: 1px; }
  .manage .iconfont {color: #ffffff; font-size: 23px; }
  .sub_top{display: none;}
  .span_cnzz {position: fixed; bottom: 0; left: 0; visibility: hidden; }
  .foot, .foot a{color: #FF9800;}
  .qd_desc {margin-bottom: 15px; color: #ffffff; text-align: center; font-size: 14px; color: #fff497; }
</style>
<script>
  window.onload = function(){
/*
    document.body.addEventListener("touchmove",function(event){
        event.preventDefault();
        event.stopPropagation();
    }, false);
    */
    document.ontouchmove = function(e){
      e.preventDefault();
    }
  }
</script>
<body>
<div class="bgcard"></div>
<div class="sub_top">
	<div class="title"><?php echo $title;?></div>
	<div class="back" id="pageback"><a href="javascript:;" onclick="history.go(-1)"><i class="iconfont icon-left-circle"></i></a></div>
  <a class="manage" href="manage.php"><i class="iconfont icon-appstore-fill"></i></a>
	
</div>
<div class="main">
<?php 

$stime=microtime(true); 
$codes = trim($_POST['code']);
$shujus = trim($_POST['txt_data']);
$shuru1 = trim($_POST['name']);
$time_creat = date("Y-m-d H:i:s",time());
if($shujus != 1){
?>
<div class="qd_text_box">
  <div class="qd_title"><h4><?php echo $qd_title; ?></h4></div>
  <div class="qd_desc"><?php echo $qd_desc; ?></div>
</div>
  <form name="queryForm" method="post" class="" action="?t=<?php echo time();?>" onsubmit="return startRequest(0);">
    <input type="hidden" name="txt_data" value="1">
    <div class="so_box" id="s11">
      <input name="name" type="text" onkeyup="this.value=this.value.replace(/[^\d\-]/,'')" class="txts" id="name" value="" placeholder="请输入手机" />
    </div>
    <?php if($ismas=="1"){ ?>
    <div class="so_box" id="s33">
      <input name="code" type="text" class="txts" id="code" placeholder="请输入验证码" onfocus="this.value=''" onBlur="startRequest(3)" />
      <div class="more" id="clearkey">
        <img src="inc/code.php?t=<?php echo date("Y-m-d-H-i-s",time());?>" id="Codes" onClick="this.src='inc/code.php?t='+new Date();"/>
      </div>
    </div>
    <?php }?>
    
    <div class="so_boxes">
      <input type="submit" name="button" class="buts" id="sub" value="签到">
    </div>
<?php 
  
 ?>
    <div id="tishi1" style="display:none;">请输入<?php echo $tiaojian1;?></div>
    <div id="tishi4" style="display:none;">认真输入4数字验证码</div>
</form>
<?php } else {
  if($ismas=="1"){
    session_start();
    if($codes!=$_SESSION['PHP_M2T']){
      webalert("请正确输入验证码！");
    }
  }
  if(!$shuru1 || empty($shuru1)){
    webalert("请输入$tiaojian1!");
  }

  if(!file_exists($file_qd_all)){
    webalert('请检查数据库文件');
  }

  // echo "<p>$shujus</p>";

  $filer = fopen($file_qd_all, "r") or  webalert('无法打开文件!');
  echo '<!--startprint--><div class="result">';
  //echo '<p>查询结果</p>';
  $a_files = file($file_qd_ok);
  $r = array();
  for($i=0; $i<count($a_files); $i++) {
    $t = str_getcsv($a_files[$i], "\t");
    $r[] = $t[1];
  }

while (!feof($filer)) {
    $ii++;
    $rows = fgets($filer);
    $rows = trim($rows);
    if ($rows) {

            $tabvs = explode("\t", $rows);
            //print_r($tabvs);
            if ("_" . $shuru1 == "_" . $tabvs[1]) {
                echo "<!-- $shuru1 == $tabvs[1] -->";
                // 查询成功后，将数据存入文件，并且提示签到成功，这样能知道签到有多少人
                $fp_qd_ok=fopen($file_qd_ok,"a+b");
                $fp_time=fopen($file_qd_time,"a+b");
                /*
                $data_array = array();
                while( ($data_line = fgets($fp)) !== false ) {
                  $data_array[] = trim($data_line);
                }
                if( in_array($shuru1, $data_array) ) {echo "提示：您已经签到过了！";} else {
                  fwrite($fp,"{$shuru1}\r\n"); 
                  fwrite($fp_time,"{$time_creat}\r\n"); 
                  

                }*/
                if( in_array($shuru1, $r) ) {echo "<h4 style='font-size: 18px; text-align: center;   font-weight: 700; color: #FF5722; padding-top: 10px;'>提示：重复签到！</h4>";} else {
                  fwrite($fp_qd_ok,"$tabvs[0]\t{$shuru1}\r\n"); 
                  fwrite($fp_time,"{$time_creat}\r\n"); 

                }
                fclose($fp);
                fclose($fp_time);
                $iae++;
                $iaf = 0;
                echo '<div class="field">';
                echomsg($tabvs[$iaf].",签到成功!",1,$success_msg);
                //echo $tabvs[$iaf]."，恭喜您签到成功";
                /* ===只有一个就不用循环了
                foreach ($tabvs as $tabu) {
                    $iaf++;
                    $iag = $iaf - 1;
                    // echo '<td class="r">'.$tabvt["$iag"].'</td>';
                    echo '<span >' . $tabu . '</span>';
                }
                */
                echo '</div>';
            }
    }
}
if($iae<1){
    echomsg("签到失败",0,$failed_msg);
}

echo '</div>';
echo '<!--endprint-->';
fclose($filer); ?>
<div class="so_boxesd">
  <input type="button" value="返 回" class="btn btn-primary btn-block" onclick="location.href='?t=back';" id="reset">
</div>
<?php }

$etime=microtime(true);//获取程序执行结束的时间
$total=$etime-$stime;   //计算差值
//echo "<div>页面执行时间：{$total} 秒</div>";
?>
</div>
<div class="foot">
  <div class="title">
    &copy;<?php echo date('Y');?>&nbsp; <a href="<?php echo $copyu;?>" target="_blank"><?php echo $copyr;?></a>
  </div> 

</div>
<script src="https://lib.baomitu.com/jquery/2.1.4/jquery.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="inc/js/wx_share.js?v=<?php echo $tts;?>"></script>
</body>
</html>